<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新用户注册</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../static/layuiadmin/style/login.css" media="all">
</head>
<body>

<form class="layui-form" action="" lay-filter="example">
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
        <div style="width: 420px" class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>新用户注册</h2>
                <p>权限管理系统新用户注册</p>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户账号<i style="color: red">*</i></label>
                    <div class="layui-input-inline">
                        <input style="width: 215px;padding-left: 10px" type="text" id="useraccount" name="useraccount"
                               placeholder="请输入6到12位的用户账号" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">用户密码<i style="color: red">*</i></label>
                    <div class="layui-input-inline">
                        <input style="width: 215px;padding-left: 10px" type="password" id="password" name="password"
                               placeholder="请输入6到12位的用户密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号码<i style="color: red">*</i></label>
                    <div class="layui-input-inline">
                        <input style="width: 215px;padding-left: 10px" type="tel" id="mobile" name="mobile"
                               placeholder="请输入号码" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">邮 箱<i style="color: red">*</i></label>
                    <div class="layui-input-inline">
                        <input style="width: 215px;padding-left: 10px" name="email" id="email" name="email"
                               placeholder="请输入邮箱" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">地 址<i style="color: red">*</i></label>
                    <div class="layui-input-inline">
                        <input style="width: 215px;padding-left: 10px" type="text" id="address" name="address"
                               placeholder="请输入用户地址" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">出生日期<i style="color: red">*</i></label>
                    <div class="layui-input-inline">
                        <input style="width: 215px;padding-left: 10px" type="date" id="birth" name="birth"
                               placeholder="请输入用户出生日期" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性 别<i style="color: red">*</i></label>
                    <div class="layui-input-block">
                        <input type="radio" id="sex1" name="sex" value="M" title="男" checked="">
                        <input type="radio" id="sex2" name="sex" value="F" title="女">
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button lay-submit id="LAY-user-reg-submit" class="layui-btn">注册</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>

            </div>
        </div>

    </div>
</form>

<script src="../../static/layuiadmin/layui/layui.js"></script>
<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
<script>
    layui.config({
        base: '../../static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function () {
        var $ = layui.$
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router()
            , layer = layui.layer;

        form.render();

        $("#useraccount").blur(function () {
            var userAccount = $("#useraccount").val();
            var reg = /^[a-zA-Z][a-zA-Z0-9]{5,11}$/;//正则表达式
            if (userAccount.length < 6 || userAccount.length > 12) {
                layer.msg('账号长度不能小于6位,大于12位!', {icon: 5,time:1000});
            } else {
                if (!reg.test(userAccount)) {
                    layer.msg('账号必须字母开头!', {icon: 5,time:1000});
                }
            }
        });
        $("#password").blur(function () {
            var userAccount = $("#password").val();
            var reg = /.*[a-zA-Z]+.*/;//正则表达式
            if (userAccount.length < 6 || userAccount.length > 12) {
                layer.msg('密码长度不能小于6位,大于12位', {icon: 5,time:1000});
            } else {
                if (!reg.test(userAccount)) {
                    layer.msg('密码必须包含字符！', {icon: 5,time:1000});
                }
            }
        });

        $("#email").blur(function () {
            var email = $("#email").val();
            var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            if (!reg.test(email)) {
                layer.msg('请输入正确的邮箱地址！', {icon: 5,time:1000});
            }
        });

        $("#mobile").blur(function () {
            var mobile = $("#mobile").val();
            var reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
            if (!reg.test(mobile)) {
                layer.msg('请输入正确的电话号码！', {icon: 5,time:1000});
            }
        });


        //调用后台登录
        $(document).on('click', '#LAY-user-reg-submit', function () {
            event.preventDefault()
            debugger

            var userInfo = form.val('example');

            // userInfo.password=md5(userInfo.password);

            $.post("../../admin/register", userInfo, function (res) {


                if (res.code == 500) {

                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg(res.message, {icon: 2, offset: "auto", time: 2000})
                    })

                } else {
                    var layer = layui.layer;
                    layer.msg('注册成功', {
                        offset: '15px'
                        , icon: 1
                        , time: 1000
                    }, function () {
                        location.href = '../../ams/loginIndex'; //跳转到登入页
                    });
                }
            });

        });


    });
</script>
</body>
</html>